<admintpl file="header" />
</head>
<body>
	<div class="wrap">
		<ul class="nav nav-tabs">
			<li><a href="{:U('AdminAppointment/index')}">预约管理</a></li>
			<li class="active"><a href="{:U('AdminAppointment/add')}">添加预约</a></li>
		</ul>
		<form method="post" id="formData" class="form-horizontal" action="{:U('AdminAppointment/add_post')}" onsubmit="return addData()">
			<fieldset>
				<div class="control-group">
					<label class="control-label" for="input-orderby">排序</label>
					<div class="controls">
						<input type="text" class="input-xlarge" id="input-orderby" name="orderby"  placeholder="数字越小排序越靠前">
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">姓名</label>
					<div class="controls">
						<input type="text" name="username" id="username">
						<span class="form-required">*</span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">性别</label>
					<div class="controls">
						<label>
							<input class="aui-radio" type="radio" value="0" name="sex1" checked>
							男</label>
						<label>
							<input class="aui-radio" type="radio" value="1" name="sex1">
							女</label>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">手机号</label>
					<div class="controls">
						<input type="tel" name="mobile" rows="10" cols="57" id="mobile">
						<span class="form-required">*</span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">详细地址</label>
					<div class="controls">
						<input type="text" name="houses_address" rows="10" cols="57" id="address">
						<span class="form-required">*</span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">服务类别</label>
					<div class="controls">
						<input type="text" name="server_type" id="server_type">
						<span class="form-required">*</span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">预约类别</label>
					<div class="controls">
						<input type="text" name="appointment_type" id="appointment_type">
						<span class="form-required">*</span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">预约时间</label>
					<div class="controls">
						<input type="text" name="order_date" id="order_date" value="{:date('Y-m-d H:i:s',time())}" class="js-datetime" style="width: 160px;">
						<span class="form-required">*</span>
					</div>
				</div>
				<div class="control-group">
				<label class="control-label">备注信息</label>
				<div class="controls">
					<input type="text" name="msg" id="msg" />
					<span class="form-required"></span>
				</div>
			</div>
				</fieldset>
			<div class="form-actions">
				<button  class="btn btn-primary" onclick="addData()">添加</button>
				<a class="btn" href="javascript:history.back(-1);">返回</a>
			</div>
		</form>
	</div>
	<script src="__PUBLIC__/js/common.js"></script>
<script>

//检测是否定义
function is_define(value)
{
	if (value == null || value == "" || value == "undefined" || value == undefined || value == "null" || value == "(null)" || value == 'NULL' || typeof (value) == 'undefined')
	{
		return false;
	}
	else
	{
		value = value + "";
		value = value.replace(/\s/g, "");
		if (value == "")
		{
			return false;
		}
		return true;
	}
}

//检测手机号
function checkMobile(mobile) {
	if (mobile.length == 0) {
		//baiyu alert('请输入手机号')
		return false;
	}
	if (mobile.length != 11) {
		//baiyu alert('请输入有效的手机号码！')
		return false;
	}
	var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
	if (!myreg.test(mobile)) {
		api.toast({
			msg : '请输入有效的手机号码！',
			duration : 2000,
			location : 'middle'
		});
		return false;
	}
	return true;
}

//提交数据
function addData(){
	var username = document.getElementById('username').value,
		mobile = document.getElementById('mobile').value,
		address = document.getElementById('address').value,
		serverType = document.getElementById('server_type').value,
			appointment_type=document.getElementById('appointment_type')
		order_date = document.getElementById('order_date').value;
		msg = document.getElementById('msg').value;
	var rad = document.getElementsByName("sex1");
	for (var i = 0; i < rad.length; i++) {
		if (rad[i].checked) {
			var sex;
			sex = rad[i].value;
		}
	}

	if (is_define(username) && is_define(sex) && is_define(mobile) && is_define(address) && is_define(serverType)&& is_define(appointment_type)&& is_define(order_date)) {
		if (!checkMobile(mobile)) {
			alert('请输入有效的手机号码！');
			return;
		}else{
			document.getElementById('formData').submit();
		}
	} else {
		alert("请输入完整信息再提交！");
		return false;
	}
}
</script>
</body>
</html>